home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2823 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: ohstpy.mps.ohio-state.edu!vancleef
  2. From: vancleef@ohstpy.mps.ohio-state.edu
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Why isn't return address in the stack protected?
  5. Message-ID: <1996Jan24.032914.8805@ohstpy>
  6. Date: 24 Jan 96 03:29:14 -0500
  7. References: <DLo4xF.MH@un.seqeb.gov.au>
  8. Organization: The Ohio State University, Department of Physics
  9.  
  10. In article <DLo4xF.MH@un.seqeb.gov.au>, al012@svtstu.seqeb.gov.au (Anthony Lee) writes:
  11. > void log_event(void)
  12. > {
  13. >      char message[256]; 
  14. >     int i;
  15. >     sprintf(message,
  16. >         "     Event, node: %d, seq:%08.8x, type:%02.2d, 
  17. > length:%03.3d, data: ",
  18. >         nodeid, me.seqno, me.type, me.length);
  19. >     for ( i = 0; i < me.length; i++)
  20. >            sprintf(&message[strlen(message)],"%02.2x 
  21. > ",me.data.array[i] & 0xff);
  22. >     printf("%s\n", message);
  23. > }
  24. > In the above code if the me.length is such that the resultant
  25. > string is longer than the size of message (> 256 bytes).  Then
  26. > my C program would happily sprintf into message.  The problem is
  27. > that it starts writing all over the stack causing the program
  28. > to fall over.  My question is why can't the run time environment
  29. > protect the stack from such access and flag an error?
  30. > -- 
  31.  
  32. Because that's the way C works. It doesn't do anything more
  33. than you specifically ask for. If it did, you wouldn't have
  34. control over your application, the compiler would. Programming
  35. in C is a double edged sword, if you don't like it you
  36. should stick to Fortran.
  37.  
  38. -Garrett
  39.  
  40.  
  41.  
  42. > Anthony Lee        These are my opinions and not SEQEB.
  43. > SEQEB                                            
  44. > 150 Charlotte Street                   ..--  __o 
  45. > Brisbane                          ....--   _ \<,_               
  46. > Qld 4000                         ____     (_)/ (_)                       
  47. >   
  48. > Australia
  49. > voice:+61 7 3407 4541            Death to the Daleks!!!!
  50. > fax:  +61 7 3407 4607
  51. > email: AL012@svtstu.seqeb.gov.au
  52.